﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IllustratedCsharp7_ch8_chapt8_6
{
    class chapt8_5_UseBaseClassReference
    {
        static void _Main()
        {
            MyDerivedClass derived = new MyDerivedClass();
            MyBaseClass mybc =  (MyBaseClass)derived;       //转换成基类
            derived.Print();    //从派生类部分调用Print
            mybc.Print();       //从基类部分调用Print
            //mybc.var1 = 5;     //错误，基类引用无法访问派生类成员
        }
    }
    class MyBaseClass                      //基类
    {
        
        public void Print()
        {
            Console.WriteLine("This is the base class.");
        }
    }

    class MyDerivedClass : MyBaseClass                   //派生类
    {
        public int var1;
       
       new public void Print()
        {
            Console.WriteLine("This is the derived class");  
           
        }
    }
}
